<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>关键计划新增</title>
    <script src="/scripts/boot.js"></script>
    <link href="/scripts/daterangepicker/js/daterangepicker.min.css" rel="stylesheet" type="text/css" />
    <script src="/scripts/daterangepicker/js/moment.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/js/jquery.daterangepicker.min.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/ux.daterangepicker.js" type="text/javascript"></script>
    <link href="/scripts/daterangepicker/css/skin.css" rel="stylesheet" type="text/css" />
</head>
<body class="bg-white">
<div id="viewForm">
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>

        <tr>
            <td class="text-titlebg"><span class="color-red">*</span>计划类型</td>
            <td>
                <select id="planType" name="planType" class="mini-combobox w250" ajaxType="post" url="/dictionary/listValues?name=plan_type" textField="value" valueField="id" errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
            </td>
            <td class="text-titlebg">
                <span class="color-red">*</span>计划名称
            </td>
            <td>
                <input type="text" name="name" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　vtype="maxLength:48"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>计划起止时间
            </td>
            <td>
                <input id="date-range1" name="ssDate"  class="uc-daterangepicker searchbox w250" />
            </td>
            <td class="text-titlebg">
                <span class="color-red">*</span>项目负责人
            </td>
            <td>
                <input name="functionaryId" id="functionaryId" class="mini-treeselect w250" onbeforenodeselect="common.beforenodeselect" expandOnLoad="true" showTreeIcon="true" valueField="id" textField="name"   parentField="pid"   required="true"   vtype="maxLength:48"  errorMode="none" onvalidation="upChoseError" requiredErrorText="请选择"/>
                <!--<input type="text" name="functionaryId" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入" vtype="maxLength:48"/>-->
            </td>

        </tr>
        <tr>

            <td class="text-titlebg">
                <span class="color-red">*</span>完成标准
            </td>
            <td>
                <input type="text" name="completeStandard" id="completeStandard" class="mini-textbox w250" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　vtype="maxLength:48"/>
            </td>
        </tr>

        <tr>
            <td class="text-titlebg noEmpty">说明</td>
            <td colspan="3" class="wp">
                <textarea name="remark" class="mini-textarea wtextarea" emptyText=""></textarea>
            </td>
        </tr>
    </table>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
    </div>
</div>
<script src="/scripts/res/js/common.js"></script>
<script type="text/javascript">
    var post_flag,form,state,datas;
    var view = {
        init: function () {
            common.areaItem.init({
                idName:'#areaItem',
                isItem: true
            });
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.parse();
            form = new mini.Form("#viewForm");
            common.company();
            common.loadTree({
                success : function(data){
                    //获取评价人
                    var functionaryId = mini.get("functionaryId");
                    functionaryId.loadList(data, "id", "pid");
                }
            });
        },
        //保存
        save: function () {
            form.validate();
            if (form.isValid() == false) return;
            if (post_flag) return;
            var data = form.getData();//获取表单多个控件的数据
            post_flag = true;
            data['plan.planType.id']=data.planType;
          //  data['plan.planType.functionaryId']=data.planType;

            data['plan.item.functionaryId']=data.functionaryId;
            delete data["functionaryId"];

            data['plan.name']=data.name;
            data['beginDate']=new Date(data.ssDate.substring(0,10));
            data['endDate']=new Date(data.ssDate.substring(data.ssDate.length-10,data.ssDate.length));

            var deadline=(new Date(data.ssDate.substring(data.ssDate.length-10,data.ssDate.length)).getTime()-new Date(data.ssDate.substring(0,10)).getTime())/(1000*60*60*24);

            data['overDay']=deadline;
            delete data["ssDate"];
            if(data.cooperateDate){
                data['cooperateBeginDate']=new Date(data.cooperateDate.substring(0,10));
                data['cooperateEndDate']=new Date(data.cooperateDate.substring(data.cooperateDate.length-10,data.cooperateDate.length));
                delete data["cooperateDate"];
            }


            $.ajax({
                url: ("/monthformation/add"),
                type: "post",
                data: data,
                success: function (msg) {
                    post_flag = false;
                    common.unmask();
                    CloseWindow("ok");
                },
                error: function (errorMsg) {
                    post_flag = false;
                    common.unmask();
                }
            });
        },
        openChoseProject:function () {
            mini.open({
                url: "/common/choseProject.html",
                title: "选择项目", width: 500, height: 400
            });
        }
    };
    view.init();
</script>
</body>
</html>